package testJdk.lambda;

import org.junit.Test;

import java.util.Comparator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-04-01 14:18:57
 */
public class LearnLambda03 {
    @Test
    public void test() {
        // 将函数 赋值给 函数对象
        Consumer<String> con = (x) -> System.out.println(x);
        con.accept("123");
    }

    @Test
    public void test2() {
        // 将函数 赋值给 函数对象
        Consumer<String> con = System.out::println;
        con.accept("123");
    }

    @Test
    public void test3() {
        // 将函数 赋值给 函数对象
        Comparator<Integer> com = (x, y) -> Integer.compare(x, y);
        int flag = com.compare(1, 2);
        System.out.println(flag);
    }

    @Test
    public void test4() {
        // 将函数 赋值给 函数对象
        Comparator<Integer> com = Integer::compare;
        int flag = com.compare(1, 2);
        System.out.println(flag);
    }

    @Test
    public void testThreadPool() {
        ExecutorService threadPool = Executors.newSingleThreadExecutor();
        threadPool.execute(() -> {
            System.out.println("123");
        });
        threadPool.execute(() -> {
            System.out.println("456");
        });
    }
}
